package user;


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class RegServlet extends HttpServlet {
    public RegServlet() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private static final String CONTENT_TYPE = "text/html; charset=GB2312";

    //Initialize global variables
    public void init() throws ServletException {
    }

    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();

        request.setCharacterEncoding("gb2312");

        regBean rBean=new regBean();
        rBean.setName(request.getParameter("name"));
        rBean.setPwd(request.getParameter("pwd"));
        rBean.setRepwd(request.getParameter("repwd"));


        String name = request.getParameter("name");
        String userPwd = request.getParameter("pwd");
        String reuserPwd = request.getParameter("repwd");
        if(userPwd.equals(reuserPwd) && !userPwd.equals("") && !name.equals("")){
            RegDAO re=new RegDAO();
            re.regUse(rBean);
            RequestDispatcher dis=request.getRequestDispatcher("regOk.jsp");
            dis.forward(request,response);
        }else{
            RequestDispatcher dis=request.getRequestDispatcher("RegError.jsp");
            dis.forward(request,response);
        }

    }


    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        this.doGet(request, response);
    }

    //Clean up resources
    public void destroy() {
    }

    private void jbInit() throws Exception {
    }
}
